package com.study.proxy;

import com.study.proxy.jdk.BuyHouseImpl;
import com.study.proxy.jdk.BuyHouse;
import com.study.proxy.jdk.BuyHouseProxy;

import java.lang.reflect.Proxy;

public class JdkProxy {

	public static void main(String[] args) {

		BuyHouse target = new BuyHouseImpl();
		BuyHouse buyHouseProxy = (BuyHouse)Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),new BuyHouseProxy(target));
		buyHouseProxy.buyHouse();
//		test();
	}

//
//	public static void test() {
//
//		try {
//			byte[] proxyClassFile = ProxyGenerator.generateProxyClass("$Proxy", BuyHouse.class.getInterfaces());
//			FileOutputStream outputStream = new FileOutputStream("BuyHouseImplProxy");
//			outputStream.write(proxyClassFile);
//			outputStream.flush();
//			outputStream.close();
//		} catch (FileNotFoundException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}

}
